package com.wwwarehouse.contract.program_operation;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.activity.base.BaseApplication;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.custom_widget.slider.RangeBar;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.contract.bean.ChooseModuleBean;
import com.wwwarehouse.contract.bean.SourceListBean;
import com.wwwarehouse.contract.core.ContractConstant;
import com.wwwarehouse.contract.event.CheckSupplyEvent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import contract.wwwarehouse.com.contract.R;
import de.greenrobot.event.EventBus;

/**
 * Created by feng.gao on 2017/9/22.
 * 人生七八问的 客户页
 * 第一次修改：Creator by zhenwang.xiang on 2017/9/24 10:36
 * Description:客户的接口接入
 */


public class SupplySeekBarFragment extends BaseFragment implements View.OnClickListener {
	private Button mConfirmBtn;
	private LinearLayout mSeekBarLayout1 , mSeekBarLayout2 , mSeekBarLayout3 , mSeekBarLayout4 , mSeekBarLayout5 , mSeekBarLayout6;
	private RangeBar rangeBar1 , rangeBar2 , rangeBar3 , rangeBar4, rangeBar5, rangeBar6;
	private ImageView imageView1 , imageView2 , imageView3 , imageView4 , imageView5 , imageView6;
	private TextView textView1 , textView2 , textView3 , textView4 , textView5 , textView6;
	private List<ChooseModuleBean.ModuleList.BeanList> listBean = new ArrayList<>();
	private List<ChooseModuleBean.ModuleList.BeanList> mCustomerCheckedList = new ArrayList<>(); //客户已选的条目
	private boolean isFunction;
	private StateLayout mStateLayout = null;
	private RelativeLayout mRl;
	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		return inflater.inflate(R.layout.seekbar_layout, container, false);
	}


	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);

//	    //假数据开始
//	    for (int i = 0; i < 6; i++) {
//		    ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
//		    beanList.setName("销售");
//		    beanList.setProgress(0);
//		    listBean.add(beanList);
//	    }
		if (getArguments() != null) {
			isFunction = getArguments().getBoolean(ContractConstant.KEY_IS_FUNCTION);
		}
		mConfirmBtn = (Button) view.findViewById(R.id.confirm_btn);
		mConfirmBtn.setOnClickListener(this);
		mConfirmBtn.setEnabled(false);
		mRl = (RelativeLayout) view.findViewById(R.id.RlBg);
		mRl.setVisibility(View.INVISIBLE);
		mStateLayout = (StateLayout) view.findViewById(R.id.gaofeng_sl_state);
		mSeekBarLayout1 = (LinearLayout) view.findViewById(R.id.seekbarlayout1);
		mSeekBarLayout2 = (LinearLayout) view.findViewById(R.id.seekbarlayout2);
		mSeekBarLayout3 = (LinearLayout) view.findViewById(R.id.seekbarlayout3);
		mSeekBarLayout4 = (LinearLayout) view.findViewById(R.id.seekbarlayout4);
		mSeekBarLayout5 = (LinearLayout) view.findViewById(R.id.seekbarlayout5);
		mSeekBarLayout6 = (LinearLayout) view.findViewById(R.id.seekbarlayout6);

		rangeBar1 = (RangeBar) mSeekBarLayout1.findViewById(R.id.custom_rangebar);
		rangeBar2 = (RangeBar) mSeekBarLayout2.findViewById(R.id.custom_rangebar);
		rangeBar3 = (RangeBar) mSeekBarLayout3.findViewById(R.id.custom_rangebar);
		rangeBar4 = (RangeBar) mSeekBarLayout4.findViewById(R.id.custom_rangebar);
		rangeBar5 = (RangeBar) mSeekBarLayout5.findViewById(R.id.custom_rangebar);
		rangeBar6 = (RangeBar) mSeekBarLayout6.findViewById(R.id.custom_rangebar);

		imageView1 = (ImageView) mSeekBarLayout1.findViewById(R.id.custom_item_iv);
		imageView2 = (ImageView) mSeekBarLayout2.findViewById(R.id.custom_item_iv);
		imageView3 = (ImageView) mSeekBarLayout3.findViewById(R.id.custom_item_iv);
		imageView4 = (ImageView) mSeekBarLayout4.findViewById(R.id.custom_item_iv);
		imageView5 = (ImageView) mSeekBarLayout5.findViewById(R.id.custom_item_iv);
		imageView6 = (ImageView) mSeekBarLayout6.findViewById(R.id.custom_item_iv);

		textView1 = (TextView) mSeekBarLayout1.findViewById(R.id.custom_item_tv);
		textView2 = (TextView) mSeekBarLayout2.findViewById(R.id.custom_item_tv);
		textView3 = (TextView) mSeekBarLayout3.findViewById(R.id.custom_item_tv);
		textView4 = (TextView) mSeekBarLayout4.findViewById(R.id.custom_item_tv);
		textView5 = (TextView) mSeekBarLayout5.findViewById(R.id.custom_item_tv);
		textView6 = (TextView) mSeekBarLayout6.findViewById(R.id.custom_item_tv);


	}



	@Override
	public void setTitle() {
		if (peekFragment() instanceof SupplySeekBarFragment) {
			mActivity.setTitle(R.string.choose_supply_title);
		}
	}

	@Override
	public void requestDatas() {
		mStateLayout.showProgressView(true);
		if (getArguments() != null) {
			if (getArguments().getSerializable(ContractConstant.KEY_BUNDLE_CHECKED_DATA) != null) {
				mCustomerCheckedList = (List<ChooseModuleBean.ModuleList.BeanList>) getArguments().getSerializable(ContractConstant.KEY_BUNDLE_CHECKED_DATA);
			}
			if (getArguments().getSerializable(ContractConstant.KEY_BUNDLE_SUPPLY_PARAMS) != null) {
				List<SourceListBean> mSourceListBeen = (List<SourceListBean>) getArguments().getSerializable(ContractConstant.KEY_BUNDLE_SUPPLY_PARAMS);
				if (mSourceListBeen != null) {
					Map<String, Object> map = new HashMap<>();
					map.put("page", 1);
					map.put("size", 10000);

					Map<String, Object> param = new HashMap<>();
					param.put("baseQuery", map);
//              param.put("buId", 260001);
					param.put("sourceList", mSourceListBeen);
					param.put("sourceModule", "PROVIDER");
					if (isFunction) {
						param.put("taskType", "function");
						if (getArguments() != null && getArguments().getString(ContractConstant.KEY_BUNDLE_CONTRACT_BUID) != null)
							param.put("buId", getArguments().getString(ContractConstant.KEY_BUNDLE_CONTRACT_BUID));
					} else {
						param.put("taskType", "task");
					}
					NoHttpUtils.httpPost(ContractConstant.PLANNING_CHOOSE_MODULE, param, mOnResponseListener, 0);
				}
			}

		}

	}

	private NoHttpUtils.OnResponseListener mOnResponseListener = new NoHttpUtils.OnResponseListener() {
		@Override
		public void onSucceed(CommonClass commonClass, int what) {
			if (what == 0) {
				if ("0".equals(commonClass.getCode())) {
					mRl.setVisibility(View.VISIBLE);
					mStateLayout.showContentView();
					ChooseModuleBean chooseModuleBean = JSON.parseObject(commonClass.getData().toString(), ChooseModuleBean.class);
					if (mCustomerCheckedList.size() > 0) {
						for (int i = 0; i < mCustomerCheckedList.size(); i++) {
							for (int j = 0; j < chooseModuleBean.getModuleList().getList().size(); j++) {
								if (mCustomerCheckedList.get(i).getCode().equals(chooseModuleBean.getModuleList().getList().get(j).getCode())) {
									chooseModuleBean.getModuleList().getList().get(j).setProgress(mCustomerCheckedList.get(i).getProgress());
								}
							}
						}
						mConfirmBtn.setEnabled(true);
						mConfirmBtn.setText("确定（100%）");
						mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
					}
					listBean = chooseModuleBean.getModuleList().getList();
					getValue();
					if (listBean.get(0).getSelected() == 1 && isFunction) {
						rangeBar1.setOnUIRangeBarChangeListener(new RangeBar.OnUIRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar2.getProgress() + rangeBar3.getProgress() + rangeBar4.getProgress() + rangeBar5.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								if (listBean.get(0).getSelected() == 1 && isFunction && rangeBar1.getProgress() == 0) {
									rangeBar1.setProgress(1);
								}
								rangeBar1.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar1.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar5.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar1.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					} else {

						rangeBar1.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar2.getProgress() + rangeBar3.getProgress() + rangeBar4.getProgress() + rangeBar5.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								rangeBar1.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar1.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar6.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar1.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					}
					if (listBean.get(1).getSelected() == 1 && isFunction) {
						rangeBar2.setOnUIRangeBarChangeListener(new RangeBar.OnUIRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar3.getProgress() + rangeBar4.getProgress() + rangeBar5.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								if (listBean.get(1).getSelected() == 1 && isFunction && rangeBar2.getProgress() == 0) {
									rangeBar2.setProgress(1);
								}
								rangeBar2.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar2.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar5.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar2.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					} else {

						rangeBar2.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar3.getProgress() + rangeBar4.getProgress() + rangeBar5.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								rangeBar2.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar2.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar6.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar2.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					}
					if (listBean.get(2).getSelected() == 1 && isFunction) {
						rangeBar3.setOnUIRangeBarChangeListener(new RangeBar.OnUIRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar2.getProgress() + rangeBar4.getProgress() + rangeBar5.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								if (listBean.get(2).getSelected() == 1 && isFunction && rangeBar3.getProgress() == 0) {
									rangeBar3.setProgress(1);
								}
								rangeBar3.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar3.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar5.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar3.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					} else {

						rangeBar3.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar2.getProgress() + rangeBar4.getProgress() + rangeBar5.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								rangeBar3.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar3.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar6.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar3.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					}
					if (listBean.get(3).getSelected() == 1 && isFunction) {
						rangeBar4.setOnUIRangeBarChangeListener(new RangeBar.OnUIRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar2.getProgress() + rangeBar3.getProgress() + rangeBar5.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								if (listBean.get(3).getSelected() == 1 && isFunction && rangeBar4.getProgress() == 0) {
									rangeBar4.setProgress(1);
								}
								rangeBar4.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar4.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar5.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar4.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					} else {

						rangeBar4.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar2.getProgress() + rangeBar3.getProgress() + rangeBar5.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								rangeBar4.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar4.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar6.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar4.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					}

					if (listBean.get(4).getSelected() == 1 && isFunction) {
						rangeBar5.setOnUIRangeBarChangeListener(new RangeBar.OnUIRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar2.getProgress() + rangeBar3.getProgress() + rangeBar4.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								if (listBean.get(4).getSelected() == 1 && isFunction && rangeBar5.getProgress() == 0) {
									rangeBar5.setProgress(1);
								}
								rangeBar5.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar5.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar5.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar5.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");
								}
							}
						});
					} else {

						rangeBar5.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar2.getProgress() + rangeBar3.getProgress() + rangeBar4.getProgress() + rangeBar6.getProgress();
								int maxProgress = 100 - total;
								rangeBar5.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar5.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar6.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar5.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					}


					if (listBean.get(5).getSelected() == 1 && isFunction) {
						rangeBar6.setOnUIRangeBarChangeListener(new RangeBar.OnUIRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar2.getProgress() + rangeBar3.getProgress() + rangeBar4.getProgress() + rangeBar5.getProgress();
								int maxProgress = 100 - total;
								if (listBean.get(5).getSelected() == 1 && isFunction && rangeBar6.getProgress() == 0) {
									rangeBar6.setProgress(1);
								}
								rangeBar6.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar6.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar5.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar6.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");
								}
							}
						});

					} else {
						rangeBar6.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
							@Override
							public void onProgressChanged(int i) {
								int total = rangeBar1.getProgress() + rangeBar2.getProgress() + rangeBar3.getProgress() + rangeBar4.getProgress() + rangeBar5.getProgress();
								int maxProgress = 100 - total;
								rangeBar6.setMaxSlideRange(maxProgress);
								if (i >= maxProgress) {
									rangeBar6.setProgress(maxProgress);
									mConfirmBtn.setEnabled(true);
									int show = total + maxProgress;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								} else {
//				    rangeBar6.setProgress(i);
									if (i == maxProgress - 1) {
										rangeBar6.setProgress(i + 1);
										mConfirmBtn.setEnabled(true);
										int show = total + i + 1;
										mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_normal_shape));
										mConfirmBtn.setText("确定（" + show + "%）");
										return;
									}
									mConfirmBtn.setEnabled(false);
									int show = total + i;
									mConfirmBtn.setBackground(mActivity.getResources().getDrawable(R.drawable.common_btn1_noclick_shape));
									mConfirmBtn.setText("确定（" + show + "%）");

								}
							}
						});
					}
				} else {
					mStateLayout.showSystemView(commonClass.getMsg() , true);
				}

			}
		}

		@Override
		public void onFailed(String result, int what) {
			mStateLayout.showSystemView(result , true);
			mStateLayout.setSystemListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					requestDatas();
				}
			});
		}

		@Override
		public void onFinish(int what) {
		}
	};

	private void getValue() {
		if (listBean != null) {

			if (listBean.size() == 1) {
				mSeekBarLayout1.setVisibility(View.VISIBLE);
				setValue(listBean , 0 , textView1 , imageView1 , rangeBar1);
				mSeekBarLayout2.setVisibility(View.GONE);
				mSeekBarLayout3.setVisibility(View.GONE);
				mSeekBarLayout4.setVisibility(View.GONE);
				mSeekBarLayout5.setVisibility(View.GONE);
				mSeekBarLayout6.setVisibility(View.GONE);
			} else if (listBean.size() == 2) {
				mSeekBarLayout1.setVisibility(View.VISIBLE);
				mSeekBarLayout2.setVisibility(View.VISIBLE);
				setValue(listBean , 0 , textView1 , imageView1 , rangeBar1);
				setValue(listBean , 1 , textView2 , imageView2 , rangeBar2);
				mSeekBarLayout3.setVisibility(View.GONE);
				mSeekBarLayout4.setVisibility(View.GONE);
				mSeekBarLayout5.setVisibility(View.GONE);
				mSeekBarLayout6.setVisibility(View.GONE);
			}else if (listBean.size() == 3) {
				mSeekBarLayout1.setVisibility(View.VISIBLE);
				mSeekBarLayout2.setVisibility(View.VISIBLE);
				mSeekBarLayout3.setVisibility(View.VISIBLE);
				setValue(listBean , 0 , textView1 , imageView1 , rangeBar1);
				setValue(listBean , 1 , textView2 , imageView2 , rangeBar2);
				setValue(listBean , 2 , textView3 , imageView3 , rangeBar3);
				mSeekBarLayout4.setVisibility(View.GONE);
				mSeekBarLayout5.setVisibility(View.GONE);
				mSeekBarLayout6.setVisibility(View.GONE);
			}else if (listBean.size() == 4) {
				mSeekBarLayout1.setVisibility(View.VISIBLE);
				mSeekBarLayout2.setVisibility(View.VISIBLE);
				mSeekBarLayout3.setVisibility(View.VISIBLE);
				mSeekBarLayout4.setVisibility(View.VISIBLE);
				setValue(listBean , 0 , textView1 , imageView1 , rangeBar1);
				setValue(listBean , 1 , textView2 , imageView2 , rangeBar2);
				setValue(listBean , 2 , textView3 , imageView3 , rangeBar3);
				setValue(listBean , 3 , textView4 , imageView4 , rangeBar4);
				mSeekBarLayout5.setVisibility(View.GONE);
				mSeekBarLayout6.setVisibility(View.GONE);
			}else if (listBean.size() == 5) {
				mSeekBarLayout1.setVisibility(View.VISIBLE);
				mSeekBarLayout2.setVisibility(View.VISIBLE);
				mSeekBarLayout3.setVisibility(View.VISIBLE);
				mSeekBarLayout4.setVisibility(View.VISIBLE);
				mSeekBarLayout5.setVisibility(View.VISIBLE);
				setValue(listBean , 0 , textView1 , imageView1 , rangeBar1);
				setValue(listBean , 1 , textView2 , imageView2 , rangeBar2);
				setValue(listBean , 2 , textView3 , imageView3 , rangeBar3);
				setValue(listBean , 3 , textView4 , imageView4 , rangeBar4);
				setValue(listBean , 4 , textView5 , imageView5 , rangeBar5);
				mSeekBarLayout6.setVisibility(View.GONE);
			}else if (listBean.size() == 6) {
				mSeekBarLayout1.setVisibility(View.VISIBLE);
				mSeekBarLayout2.setVisibility(View.VISIBLE);
				mSeekBarLayout3.setVisibility(View.VISIBLE);
				mSeekBarLayout4.setVisibility(View.VISIBLE);
				mSeekBarLayout5.setVisibility(View.VISIBLE);
				mSeekBarLayout6.setVisibility(View.VISIBLE);
				setValue(listBean , 0 , textView1 , imageView1 , rangeBar1);
				setValue(listBean , 1 , textView2 , imageView2 , rangeBar2);
				setValue(listBean , 2 , textView3 , imageView3 , rangeBar3);
				setValue(listBean , 3 , textView4 , imageView4 , rangeBar4);
				setValue(listBean , 4 , textView5 , imageView5 , rangeBar5);
				setValue(listBean , 5 , textView6, imageView6 , rangeBar6);
			}



		}
	}

	private void setValue(final List<ChooseModuleBean.ModuleList.BeanList> listBean , final int position , TextView textView , ImageView imageView , final RangeBar rangeBar) {
		textView.setText(listBean.get(position).getName());
		if (listBean.get(position).getImageUrl() != null && listBean.get(position).getImageUrl().getSelectedUrl() != null) {
			BaseApplication.getApplicationInstance().displayImg(listBean.get(position).getImageUrl().getSelectedUrl(), imageView);
		}
		rangeBar.setProgress(listBean.get(position).getProgress());

		mSeekBarLayout1.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
			@Override
			public void onGlobalLayout() {
				rangeBar.setProgress(listBean.get(position).getProgress());

//				setReachWidth(reachWidth);
				mSeekBarLayout1.getViewTreeObserver().removeOnGlobalLayoutListener(this);
			}
		});
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.confirm_btn) {
			List<ChooseModuleBean.ModuleList.BeanList> mCustomerCheckedList = new ArrayList<>();
			if (listBean.size() == 1) {
				if (rangeBar1.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
					beanList.setName(listBean.get(0).getName());
					beanList.setCode(listBean.get(0).getCode());
					beanList.setProgress(rangeBar1.getProgress());
					if (listBean.get(0).getImageUrl() != null) {
						beanList.setImageUrl(listBean.get(0).getImageUrl());
					}
					mCustomerCheckedList.add(beanList);
				}
			} else if (listBean.size() == 2) {
				if (rangeBar1.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
					beanList.setName(listBean.get(0).getName());
					beanList.setCode(listBean.get(0).getCode());
					beanList.setProgress(rangeBar1.getProgress());
					if (listBean.get(0).getImageUrl() != null) {
						beanList.setImageUrl(listBean.get(0).getImageUrl());
					}
					mCustomerCheckedList.add(beanList);
				}

				if (rangeBar2.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList1 = new ChooseModuleBean.ModuleList.BeanList();
					beanList1.setName(listBean.get(1).getName());
					beanList1.setCode(listBean.get(1).getCode());
					beanList1.setProgress(rangeBar2.getProgress());
					if (listBean.get(1).getImageUrl() != null) {
						beanList1.setImageUrl(listBean.get(1).getImageUrl());
					}
					mCustomerCheckedList.add(beanList1);
				}
			} else if (listBean.size() == 3) {
				if (rangeBar1.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
					beanList.setName(listBean.get(0).getName());
					beanList.setCode(listBean.get(0).getCode());
					beanList.setProgress(rangeBar1.getProgress());
					if (listBean.get(0).getImageUrl() != null) {
						beanList.setImageUrl(listBean.get(0).getImageUrl());
					}
					mCustomerCheckedList.add(beanList);
				}

				if (rangeBar2.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList1 = new ChooseModuleBean.ModuleList.BeanList();
					beanList1.setName(listBean.get(1).getName());
					beanList1.setCode(listBean.get(1).getCode());
					beanList1.setProgress(rangeBar2.getProgress());
					if (listBean.get(1).getImageUrl() != null) {
						beanList1.setImageUrl(listBean.get(1).getImageUrl());
					}
					mCustomerCheckedList.add(beanList1);
				}


				if (rangeBar3.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList2 = new ChooseModuleBean.ModuleList.BeanList();
					beanList2.setName(listBean.get(2).getName());
					beanList2.setCode(listBean.get(2).getCode());
					beanList2.setProgress(rangeBar3.getProgress());
					if (listBean.get(2).getImageUrl() != null) {
						beanList2.setImageUrl(listBean.get(2).getImageUrl());
					}
					mCustomerCheckedList.add(beanList2);
				}

			} else if (listBean.size() == 4) {
				if (rangeBar1.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
					beanList.setName(listBean.get(0).getName());
					beanList.setCode(listBean.get(0).getCode());
					beanList.setProgress(rangeBar1.getProgress());
					if (listBean.get(0).getImageUrl() != null) {
						beanList.setImageUrl(listBean.get(0).getImageUrl());
					}
					mCustomerCheckedList.add(beanList);
				}

				if (rangeBar2.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList1 = new ChooseModuleBean.ModuleList.BeanList();
					beanList1.setName(listBean.get(1).getName());
					beanList1.setCode(listBean.get(1).getCode());
					beanList1.setProgress(rangeBar2.getProgress());
					if (listBean.get(1).getImageUrl() != null) {
						beanList1.setImageUrl(listBean.get(1).getImageUrl());
					}
					mCustomerCheckedList.add(beanList1);
				}


				if (rangeBar3.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList2 = new ChooseModuleBean.ModuleList.BeanList();
					beanList2.setName(listBean.get(2).getName());
					beanList2.setCode(listBean.get(2).getCode());
					beanList2.setProgress(rangeBar3.getProgress());
					if (listBean.get(2).getImageUrl() != null) {
						beanList2.setImageUrl(listBean.get(2).getImageUrl());
					}
					mCustomerCheckedList.add(beanList2);
				}


				if (rangeBar4.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList3 = new ChooseModuleBean.ModuleList.BeanList();
					beanList3.setName(listBean.get(3).getName());
					beanList3.setCode(listBean.get(3).getCode());
					beanList3.setProgress(rangeBar4.getProgress());
					if (listBean.get(3).getImageUrl() != null) {
						beanList3.setImageUrl(listBean.get(3).getImageUrl());
					}
					mCustomerCheckedList.add(beanList3);
				}
			} else if (listBean.size() == 5) {
				if (rangeBar1.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
					beanList.setName(listBean.get(0).getName());
					beanList.setCode(listBean.get(0).getCode());
					beanList.setProgress(rangeBar1.getProgress());
					if (listBean.get(0).getImageUrl() != null) {
						beanList.setImageUrl(listBean.get(0).getImageUrl());
					}
					mCustomerCheckedList.add(beanList);
				}

				if (rangeBar2.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList1 = new ChooseModuleBean.ModuleList.BeanList();
					beanList1.setName(listBean.get(1).getName());
					beanList1.setCode(listBean.get(1).getCode());
					beanList1.setProgress(rangeBar2.getProgress());
					if (listBean.get(1).getImageUrl() != null) {
						beanList1.setImageUrl(listBean.get(1).getImageUrl());
					}
					mCustomerCheckedList.add(beanList1);
				}


				if (rangeBar3.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList2 = new ChooseModuleBean.ModuleList.BeanList();
					beanList2.setName(listBean.get(2).getName());
					beanList2.setCode(listBean.get(2).getCode());
					beanList2.setProgress(rangeBar3.getProgress());
					if (listBean.get(2).getImageUrl() != null) {
						beanList2.setImageUrl(listBean.get(2).getImageUrl());
					}
					mCustomerCheckedList.add(beanList2);
				}


				if (rangeBar4.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList3 = new ChooseModuleBean.ModuleList.BeanList();
					beanList3.setName(listBean.get(3).getName());
					beanList3.setCode(listBean.get(3).getCode());
					beanList3.setProgress(rangeBar4.getProgress());
					if (listBean.get(3).getImageUrl() != null) {
						beanList3.setImageUrl(listBean.get(3).getImageUrl());
					}
					mCustomerCheckedList.add(beanList3);
				}


				if (rangeBar5.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList4 = new ChooseModuleBean.ModuleList.BeanList();
					beanList4.setName(listBean.get(4).getName());
					beanList4.setCode(listBean.get(4).getCode());
					beanList4.setProgress(rangeBar5.getProgress());
					if (listBean.get(4).getImageUrl() != null) {
						beanList4.setImageUrl(listBean.get(4).getImageUrl());
					}
					mCustomerCheckedList.add(beanList4);
				}

			} else if (listBean.size() == 6) {
				if (rangeBar1.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
					beanList.setName(listBean.get(0).getName());
					beanList.setCode(listBean.get(0).getCode());
					beanList.setProgress(rangeBar1.getProgress());
					if (listBean.get(0).getImageUrl() != null) {
						beanList.setImageUrl(listBean.get(0).getImageUrl());
					}
					mCustomerCheckedList.add(beanList);
				}

				if (rangeBar2.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList1 = new ChooseModuleBean.ModuleList.BeanList();
					beanList1.setName(listBean.get(1).getName());
					beanList1.setCode(listBean.get(1).getCode());
					beanList1.setProgress(rangeBar2.getProgress());
					if (listBean.get(1).getImageUrl() != null) {
						beanList1.setImageUrl(listBean.get(1).getImageUrl());
					}
					mCustomerCheckedList.add(beanList1);
				}


				if (rangeBar3.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList2 = new ChooseModuleBean.ModuleList.BeanList();
					beanList2.setName(listBean.get(2).getName());
					beanList2.setCode(listBean.get(2).getCode());
					beanList2.setProgress(rangeBar3.getProgress());
					if (listBean.get(2).getImageUrl() != null) {
						beanList2.setImageUrl(listBean.get(2).getImageUrl());
					}
					mCustomerCheckedList.add(beanList2);
				}


				if (rangeBar4.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList3 = new ChooseModuleBean.ModuleList.BeanList();
					beanList3.setName(listBean.get(3).getName());
					beanList3.setCode(listBean.get(3).getCode());
					beanList3.setProgress(rangeBar4.getProgress());
					if (listBean.get(3).getImageUrl() != null) {
						beanList3.setImageUrl(listBean.get(3).getImageUrl());
					}
					mCustomerCheckedList.add(beanList3);
				}


				if (rangeBar5.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList4 = new ChooseModuleBean.ModuleList.BeanList();
					beanList4.setName(listBean.get(4).getName());
					beanList4.setCode(listBean.get(4).getCode());
					beanList4.setProgress(rangeBar5.getProgress());
					if (listBean.get(4).getImageUrl() != null) {
						beanList4.setImageUrl(listBean.get(4).getImageUrl());
					}
					mCustomerCheckedList.add(beanList4);
				}


				if (rangeBar6.getProgress() != 0) {
					ChooseModuleBean.ModuleList.BeanList beanList5 = new ChooseModuleBean.ModuleList.BeanList();
					beanList5.setName(listBean.get(5).getName());
					beanList5.setCode(listBean.get(5).getCode());
					beanList5.setProgress(rangeBar6.getProgress());
					if (listBean.get(5).getImageUrl() != null) {
						beanList5.setImageUrl(listBean.get(5).getImageUrl());
					}
					mCustomerCheckedList.add(beanList5);
				}

			}

			EventBus.getDefault().post(new CheckSupplyEvent(mCustomerCheckedList));
			popFragment();
		}

	}
}
